<?php
/**
 * Created by JetBrains PhpStorm.
 * User: porterzhang
 * Date: 13-3-5 下午4:44
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}
include_once 'forum.php';
class cloud_api {
    function common() { }

    function output() {
        $variable = array();
        //判断是否缺少参数
        if (empty($_GET['rid']) || empty($_GET['afids'])|| empty($_GET['cadid'])) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '1001'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }

        $afids_array = explode(",", $_GET['afids']);
        foreach ($afids_array as $key => $value) {
            $app_function=C::t('#cloud#cloud_app_function')->app_function_info($value);
            if(empty($app_function)){
                 continue;
            }
 
            if ($app_function['fpid'] > 0) { //判断这个功能是否有父id
                $vluseparent = C::t('#cloud#cloud_role_purview')->role_purviews_find($_GET['rid'],$_GET['cadid'],$app_function['fpid']);
                if(empty($vluseparent)){
		    
                    $app_pfunction=C::t('#cloud#cloud_app_function')->app_function_fpid_info($app_function['fpid']);
		 
                    $data=array(
                        'rid'=>$_GET['rid'],
                        'fid'=>$app_pfunction['fid'],
                        'fpid'=>$app_pfunction['fpid'],
                        'name'=>$app_pfunction['name'],
                        'linkurl'=>$app_pfunction['linkurl'],
                        'icon'=>$app_pfunction['icon'],
                        'sort'=>$app_pfunction['sort'],
                        'cadid'=>$_GET['cadid'],
                    );
                    C::t('#cloud#cloud_role_purview')->insert($data);
                }
            }
            $data=array(
                'rid'=>$_GET['rid'],
                'fid'=>$app_function['fid'],
                'fpid'=>$app_function['fpid'],
                'name'=>$app_function['name'],
                'linkurl'=>$app_function['linkurl'],
                'icon'=>$app_function['icon'],
                'sort'=>$app_function['sort'],
                'cadid'=>$_GET['cadid'],
            );
            C::t('#cloud#cloud_role_purview')->insert($data);
        }
        //正常返回
        $variable = array(
            'messagestr' => lang('plugin/cloud', '23002'),
        );
        cloud_core::result(cloud_core::variable($variable));
    }
}

?>

